home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15275 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Implementation of 'strncmpi' function needed
  5. Date: 18 Apr 1996 07:13:05 GMT
  6. Organization: systems hk
  7. Message-ID: <4l4q21$qtv@nadine.teleport.com>
  8. NNTP-Posting-Host: ip-pdx07-11.teleport.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  13.  
  14. Howdy,
  15.  
  16. I have to use a quasi-C implementation that does not include
  17. a 'strncmpi' function, and therefore have created the following
  18. function to accomplish the task.  However, I realize it is as
  19. inefficient in execution speed as it is efficient in trashing
  20. memory with numerous allocates/deallocates.  I was wondering if
  21. anyone had suggestions for a more elegant/efficient solution,
  22. or has the 'strncmpi' C source I could plagarize (assembler is
  23. of no use, since the implementation does not allow for it).
  24. Thanks for your time.
  25.  
  26. Yours, Geoff Houck
  27.  
  28. /*-------------------------------------------------+
  29. strncmpi -    case-insensitive 'strncmp' function
  30. +-------------------------------------------------*/
  31. int    strncmpi ( char *astr, char *bstr, int len )
  32. {
  33.   char        *ta, *tb;
  34.   int        la, lb;
  35.   int        cmp;
  36.   
  37.   la = strlen( astr );
  38.   lb = strlen( bstr );
  39.   
  40.   ta = malloc( la+1 );
  41.   tb = malloc( lb+1 );
  42.   
  43.   strcpy( ta,astr );
  44.   strcpy( tb,bstr );
  45.   
  46.   strupr( ta );
  47.   strupr( tb );
  48.   
  49.   cmp = strncmp( ta,tb,len );
  50.   
  51.   free( ta );
  52.   free( tb );
  53.   
  54.   return( cmp );
  55. }
  56.  
  57.  
  58.  
  59.